/* This file is part of Gwt--Calendar.
 *
 * Gwt--Calendar is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gwt--Calendar is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Gwt--Calendar.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.vertixtech.gwt.gwtcalendar.server.requestFactory;

import com.google.web.bindery.requestfactory.shared.Locator;
import com.vertixtech.gwt.gwtcalendar.server.domain.AbstractDomain;

/**
 * Generic @Locator for objects that extend {@link com.vertixtech.innerview.sprinkle.server.domain.WorkspaceModel}
 * 
 * @author Asaf Shakarchi
 */
public class DomainLocator extends Locator<AbstractDomain, Long> {
	@Override
	public AbstractDomain create(Class<? extends AbstractDomain> clazz) {
		try {
			return clazz.newInstance();
		} catch (InstantiationException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public AbstractDomain find(Class<? extends AbstractDomain> clazz, Long id) {
		//TODO: This should be overridden and implemented according to the server requirements
		return null;
	}

	@Override
	public Class<AbstractDomain> getDomainType() {
		// Never called
		return null;
	}

	@Override
	public Long getId(AbstractDomain domain) {
		return domain.getId();
	}

	@Override
	public Class<Long> getIdType() {
		return Long.class;
	}

	@Override
	public Object getVersion(AbstractDomain domain) {
		return domain.getVersion();
	}
}
